﻿<?php
	require('include/config.php');
	$error = 0;
	if(isset($_GET['id']) == true){
		if(is_numeric($_GET['id']) == false){
			$error = 1;
		}
		if($error == 1){
			header("Location: http://".$_SERVER['HTTP_HOST']);
		}else{
			$validcat = $_GET['id'];
		}
	}else{
		$validcat = 0;
		header("Location: http://".$_SERVER['HTTP_HOST']);
	}
	require('include/header.php');
	$sql="SELECT * FROM categories;";
	$result = mysql_query($sql);
	while($row = mysql_fetch_assoc($result)){
		if($validcat == $row['id']){
			echo "<strong>".$row['cat']."</strong><br />";
			$entriessql = "SELECT * FROM entries WHERE cat_id = ".$validcat.
				" ORDER BY dateposted DESC";
			$entriesres = mysql_query($entriessql);
			$numrows_entries=mysql_num_rows($entriesres);
			echo "<ul>";
			if($numrows_entries==0){
				echo "<i>No Entries!</i>";
			}else{
				while($entriesrow=mysql_fetch_assoc($entriesres)){
					echo "<li>".date("D jS F Y g.iA", strtotime($entriesrow['dateposted'])).
					" - <a href='viewentry.php?id=".$entriesrow['id']."'>".$entriesrow['subject'].
					"</a></li>";
				}
			}
			echo "</ul>";
		}else{
			echo "<a href = viewcat.php?id=".$row['id']."'>".$row['cat'].
				"</a><br />";
		}
	}
	require('include/footer.php');
?>